package roborally.model;

import roborally.*;
import roborally.Exceptions.IllegalAmountException;
import roborally.Exceptions.IllegalDestinationException;

/**
 * An interface that implements IFacade and makes connection between IRobots and the methods in the class Robot.java.
 * 
 * @version 1.34
 * @author Michiel Ruelens & Dieter Naten
 */

public class Facade implements IFacade {

	@Override
	public IRobot createRobot(long x, long y, int orientation, double energy) {
		try{
		IRobot robot = (IRobot) new Robot(x,y,orientation, energy);
		return robot;
		}
		catch(IllegalDestinationException exc)
		{
			System.out.println("IllegalDestinationException thrown. Details: Destination="+exc.getDestination()+", Type="+exc.getType());
			return null;
		}
		
		
	}

	@Override
	public long getX(IRobot robot) {
		long X = robot.getX();
		return X;
	}

	@Override
	public long getY(IRobot robot) {
		long Y = robot.getY();
		return Y;
	}

	@Override
	public int getOrientation(IRobot robot) {
		int orientation = robot.getOrientation();
		return orientation;
	}

	@Override
	public void move(IRobot robot) {
		try{
		robot.move();
		}
		catch(IllegalAmountException exc){
			Robot excRobot = exc.getRobot();
			assert(!Robot.isValidXCoordinate(excRobot.getX()+exc.getAmount()) 
				|| !Robot.isValidYCoordinate(excRobot.getY()+exc.getAmount()));
			System.out.println("The destination coordinate is not a valid one. Leaving the board is not allowed.");
			//Nothing else will be done as the move is not executed.
			}
	}

	@Override
	public void turnClockwise(IRobot robot) {
		robot.turnClockwise();
	}
	
	@Override
	public void turnAntiClockwise(IRobot robot) {
		robot.turnAntiClockwise();
	}


	@Override
	public double getEnergy(IRobot robot) {
		double energy = robot.getEnergy();
		return energy;
	}

	@Override
	public void recharge(IRobot robot, double energyAmount) {
		robot.recharge(energyAmount);
	}

	@Override
	public int isGetEnergyRequiredToReachAndMoveNextTo16Plus() {
		return 0;
	}

	@Override
	public int isGetEnergyRequiredToReachAndMoveNextTo16Plus(IRobot robot, IRobot robot2) {
		int energy = robot.isGetEnergyRequiredToReachAndMoveNextTo16Plus();
		return energy;
	}

	@Override
	public double getEnergyRequiredToReach(IRobot robot, long x, long y) {
		double energyRequired = robot.getEnergyRequiredToReach(x, y);
		return energyRequired;
	}

	@Override
	public void moveNextTo(IRobot robot, IRobot robot2) {
	    robot.moveNextTo(robot, robot2);
	}

}
